package cn.edu.nuc.ssm.service.impl;

import cn.edu.nuc.ssm.dao.CategoryMapper;
import cn.edu.nuc.ssm.dao.PayIncomeMapper;
import cn.edu.nuc.ssm.dto.*;
import cn.edu.nuc.ssm.entity.Category;
import cn.edu.nuc.ssm.service.ReportService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Administrator on 2017/4/15.
 */
@Service
public class ReportServiceImpl implements ReportService{

    @SuppressWarnings("SpringJavaAutowiringInspection")
    @Autowired
    private PayIncomeMapper payIncomeMapper;

    @SuppressWarnings("SpringJavaAutowiringInspection")
    @Autowired
    private CategoryMapper categoryMapper;

    @Override
    public SumShouZhiDto sumShouZhi(int uid,String year) {

        List<SumShouDto> sumShouDtos = payIncomeMapper.findbyUidSumShou(uid, year);
        List<SumZhiDto> sumZhiDtos = payIncomeMapper.findbyUidSumZhi(uid, year);

        SumShouZhiDto sumShouZhiDto = new SumShouZhiDto();
        sumShouZhiDto.setSumshou(sumShouDtos.get(0));
        sumShouZhiDto.setSumzhi(sumZhiDtos.get(0));

        return sumShouZhiDto;
    }

    @Override
    public SumjiduShouZhiDto sumShouZhiByJidu(int uid, String year) {
        List<SumJiduShouDto> jiduShouDtoList = payIncomeMapper.findbyUidSumShouByJidu(uid, year);
        List<SumJiduZhiDto> sumJiduZhiDtoList = payIncomeMapper.findbyUidSumZhiByJidu(uid, year);

        SumjiduShouZhiDto sumjiduShouZhiDto = new SumjiduShouZhiDto();
        SumJiduShouDto[] sumJiduShouDtoList = sumjiduShouZhiDto.getSumJiduShouDtoList();
        SumJiduZhiDto[] sumjiduZhiDtoList = sumjiduShouZhiDto.getSumJiduZhiDtoList();
        for (SumJiduShouDto list:jiduShouDtoList){
            if (list.getJidu()==1){
                sumJiduShouDtoList[0]=list;
            }
            if (list.getJidu()==2){
                sumJiduShouDtoList[1]=list;
            }
            if (list.getJidu()==3){
                sumJiduShouDtoList[2]=list;
            }
            if (list.getJidu()==4){
                sumJiduShouDtoList[3]=list;
            }

        }
        for (SumJiduZhiDto list:sumJiduZhiDtoList){
            if (list.getJidu()==1){
                sumjiduZhiDtoList[0]=list;
            }
            if (list.getJidu()==2){
                sumjiduZhiDtoList[1]=list;
            }
            if (list.getJidu()==3){
                sumjiduZhiDtoList[2]=list;
            }
            if (list.getJidu()==4){
                sumjiduZhiDtoList[3]=list;
            }
        }
        return sumjiduShouZhiDto;
    }

    @Override
    public SumMonthShouZhiDto sumShouZhiByMonth(int uid, String year) {
        List<SumMonthShouDto> findsumMonthShouDtos = payIncomeMapper.findbyUidSumShouByMonth(uid, year);
        List<SumMonthZhiDto> findsumMonthZhiDtos = payIncomeMapper.findbyUidSumZhiByMonth(uid, year);

        SumMonthShouZhiDto sumMonthShouZhiDto = new SumMonthShouZhiDto();
        SumMonthShouDto[] sumMonthShouDtoList = sumMonthShouZhiDto.getSumMonthShouDtoList();
        SumMonthZhiDto[] sumMonthZhiDtoList = sumMonthShouZhiDto.getSumMonthZhiDtoList();
        for (SumMonthShouDto list:findsumMonthShouDtos){
            if (list.getMonth()==1){
                sumMonthShouDtoList[0]=list;
            }
            if (list.getMonth()==2){
                sumMonthShouDtoList[1]=list;
            }
            if (list.getMonth()==3){
                sumMonthShouDtoList[2]=list;
            }
            if (list.getMonth()==4){
                sumMonthShouDtoList[3]=list;
            }
            if (list.getMonth()==5){
                sumMonthShouDtoList[4]=list;
            }
            if (list.getMonth()==6){
                sumMonthShouDtoList[5]=list;
            }
            if (list.getMonth()==7){
                sumMonthShouDtoList[6]=list;
            }
            if (list.getMonth()==8){
                sumMonthShouDtoList[7]=list;
            }
            if (list.getMonth()==9){
                sumMonthShouDtoList[8]=list;
            }
            if (list.getMonth()==10){
                sumMonthShouDtoList[9]=list;
            }
            if (list.getMonth()==11){
                sumMonthShouDtoList[10]=list;
            }
            if (list.getMonth()==12){
                sumMonthShouDtoList[11]=list;
            }

        }
        for (SumMonthZhiDto list:findsumMonthZhiDtos){
            if (list.getMonth()==1){
                sumMonthZhiDtoList[0]=list;
            }
            if (list.getMonth()==2){
                sumMonthZhiDtoList[1]=list;
            }
            if (list.getMonth()==3){
                sumMonthZhiDtoList[2]=list;
            }
            if (list.getMonth()==4){
                sumMonthZhiDtoList[3]=list;
            }
            if (list.getMonth()==5){
                sumMonthZhiDtoList[4]=list;
            }
            if (list.getMonth()==6){
                sumMonthZhiDtoList[5]=list;
            }
            if (list.getMonth()==7){
                sumMonthZhiDtoList[6]=list;
            }
            if (list.getMonth()==8){
                sumMonthZhiDtoList[7]=list;
            }
            if (list.getMonth()==9){
                sumMonthZhiDtoList[8]=list;
            }
            if (list.getMonth()==10){
                sumMonthZhiDtoList[9]=list;
            }
            if (list.getMonth()==11){
                sumMonthZhiDtoList[10]=list;
            }
            if (list.getMonth()==12){
                sumMonthZhiDtoList[11]=list;
            }
        }
        return sumMonthShouZhiDto;
    }

    @Override
    public ZhiTypeNameAndmoneyArrDto sumfindbyUidSumZhiByYearAndType(int uid, String year) {
        List<ZhiTypeNameAndmoneyDto> zhiTypeNameAndmoneyDtos = payIncomeMapper.findbyUidSumZhiByYearAndType(uid, year);

        List<Category> categories = categoryMapper.findbyCategoryBelongAndUid(1, uid);
        ZhiTypeNameAndmoneyArrDto zhiTypeNameAndmoneyArrDto = new ZhiTypeNameAndmoneyArrDto(categories,zhiTypeNameAndmoneyDtos);

        return zhiTypeNameAndmoneyArrDto;
    }
    //按照类型分类统计某个月的支出金额
    @Override
    public ZhiTypeNameAndmoneyArrDto sumfindbyUidSumZhiByMonthAndType(int uid, String year,String month) {
        List<ZhiTypeNameAndmoneyDto> zhiTypeNameAndmoneyDtos = payIncomeMapper.findbyUidSumZhiByMonthAndType(uid, year,month);

        List<Category> categories = categoryMapper.findbyCategoryBelongAndUid(1, uid);
        ZhiTypeNameAndmoneyArrDto zhiTypeNameAndmoneyArrDto = new ZhiTypeNameAndmoneyArrDto(categories,zhiTypeNameAndmoneyDtos);

        return zhiTypeNameAndmoneyArrDto;
    }
    //按照类型分类统计某个计度的支出金额
    @Override
    public ZhiTypeNameAndmoneyArrDto sumfindbyUidSumZhiByJiduAndType(int uid, String year, Integer quarter) {

        List<ZhiTypeNameAndmoneyDto> zhiTypeNameAndmoneyDtos = payIncomeMapper.findbyUidSumZhiByJiduAndType(uid, year, quarter);

        List<Category> categories = categoryMapper.findbyCategoryBelongAndUid(1, uid);
        ZhiTypeNameAndmoneyArrDto zhiTypeNameAndmoneyArrDto = new ZhiTypeNameAndmoneyArrDto(categories,zhiTypeNameAndmoneyDtos);

        return zhiTypeNameAndmoneyArrDto;
    }

    @Override
    public ConsumeAnalyDtoArr fenxiZhiByUidAndType(@Param("uid") Integer uid, @Param("year") String year) {

        //TODO
        List<Category> categories = categoryMapper.findbyCategoryBelongAndUidIsNULL(1);

        List<ConsumeAnalyDto> consumeAnalyDtos = payIncomeMapper.fenxiZhiByUidAndType(uid, year);
        ConsumeAnalyDtoArr consumeAnalyDtoArr = new ConsumeAnalyDtoArr(categories,consumeAnalyDtos);
        return consumeAnalyDtoArr;
    }
    @Override
   public  ConsumeAnalyDtoArr fenxiZhiByType( @Param("year") String year){

       List<Category> categories = categoryMapper.findbyCategoryBelongAndUidIsNULL(1);

       List<ConsumeAnalyDto> consumeAnalyDtos = payIncomeMapper.fenxiZhiByType(year);
       ConsumeAnalyDtoArr consumeAnalyDtoArr = new ConsumeAnalyDtoArr(categories,consumeAnalyDtos);
       return consumeAnalyDtoArr;

   }
}
